﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CompareArea
{
    class Program
    {
        static void Main(string[] args)
        {
            /* Pseudocode for "Compare area of 2 rectangles"
             * Display "This program will compare the area of 2 rectangles and tell which one is bigger"
             * Display "Please provide the width of the first rectangle:"
             * input width1
             * Display Please provide the length of the first rectangle:"
             * input lenght1
             * Display "Now provide the width of the second rectangle:"
             * input width2
             * Display "Finaly the lenght of the second rectangle:"
             * input lenght2
             * method calculateAndCompareAreas
             * Display area1 area2 differences
             * Ask to run the program again
             * END OF PROGRAM
             */
            double width1 = 0, width2 = 0, length1 = 0, length2 = 0, area1 = 0, area2 = 0;
            string largerArea = " ", loop = "Y";
            print("This program will allow you to calculate the area of 2 rectangles and display the differences");
            while (loop.ToUpper() == "Y")
            {
                print("Please provide the width of the first rectangle:");
                getMeasure(ref width1);
                print("Provide the lenght now:");
                getMeasure(ref length1);
                print("Thank you, now provide the width for the second one:");
                getMeasure(ref width2);
                print("And last, provide the lenght of the second rectangle:");
                getMeasure(ref length2);
                processNumbers(ref area1, ref area2, width1, width2, length1, length2, ref largerArea);
                Console.WriteLine("{0}\nThe total area for the first rectangle is {1}\nWith a width of {2} and a lenght of {3}.\n\nThe total area for the second rectangle is {4}\nWith a width of {5} and a lenght of {6}.", largerArea, area1, width1, length1, area2, width2, length2);
                print("If you would like to compare 2 more rectangles type the letter Y, if not type anything else to end the program.");
                loop = Console.ReadLine();
            }
        }
        static void processNumbers(ref double area1, ref double area2, double width1, double width2, double length1, double length2, ref string largerArea)
        {
            area1 = width1 * length1;
            area2 = width2 * length2;
            if (area1 == area2)
            {
                largerArea = "Both rectangles have the same area.";
            }
            else if (area1 > area2)
            {
                largerArea = "The first rectangle has a larger area.";
            }
            else if (area1 < area2)
            {
                largerArea = "the second rectangle has a larger area.";
            }
        }
        static void getMeasure(ref double measure)
        {
            while (!double.TryParse(Console.ReadLine(), out measure))
            {
                print("The number you have provided is invalid, try again");
            }
        }
        static void print(string t)
        {
            Console.WriteLine("\n{0}",t);
        }
    }
}
